//
//  MSProjectRadarViewController.m
//  SocietySale
//
//  Created by Mike on 16/11/18.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSProjectRadarViewController.h"
#import "MSProjectRadarTableVC.h"
#import "MSSelectRemindViewController.h"

@interface MSProjectRadarViewController ()
@property (nonatomic, copy) NSString       *projectRadarFile;
@property (nonatomic, strong) MSProjectRadarTableVC *tableVC;

@end

@implementation MSProjectRadarViewController

- (void)initNavigationBar{
    [super initNavigationBar];
    leftBarBtn.hidden = NO;
    titleLable.text = @"项目雷达";
}

- (void)initUI{
    self.tableVC = [[MSProjectRadarTableVC alloc] initWithStyle:UITableViewStyleGrouped];
    self.tableVC.view.frame = self.contentView.bounds;
    self.tableVC.enableRefresh = NO;
    self.tableVC.enableRequest = NO;
    self.tableVC.delegate = (id)self;
    self.tableVC.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.contentView addSubview:self.tableVC.view];
}

- (void)testDataFunc{
    NSString*documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) firstObject];
    self.projectRadarFile = [documentsPath stringByAppendingPathComponent:@"projectRadarFile.plist"];
    NSFileManager* fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:self.projectRadarFile]) {
        self.tableVC.dataArray = [[NSMutableArray alloc] initWithContentsOfFile:self.projectRadarFile];
    }
    else{
        NSMutableArray *dataArray = [[NSMutableArray alloc] initWithCapacity:0];
        self.tableVC.dataArray = [@[dataArray,dataArray] mutableCopy];
    }
}

- (void)updateViewController:(NSNotification *)note {
    NSDictionary *responseDic = note.userInfo;
    if (responseDic[Receiver]==self.VctrID) {
        if (responseDic[@"AccountList"]!=nil){
            self.tableVC.dataArray = responseDic[@"AccountList"];
        }
    }
}

- (void)clickAddSectionIndex:(NSInteger)sectionIndex{
    MSSelectRemindViewController *vc = [[MSSelectRemindViewController alloc] init];
    vc.remindtype = sectionIndex==10? RemindType_Change:RemindType_Update;
    vc.ChoicBlock = ^(NSMutableArray *resultArray){
        [_tableVC.dataArray replaceObjectAtIndex:sectionIndex-10 withObject:resultArray];
        [_tableVC.tableView reloadData];
        [_tableVC.dataArray writeToFile:self.projectRadarFile atomically:YES];
    };
    [rootNavigation pushViewController:vc animated:YES];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

@end
